/**
 * 任务配置信息加载初始化
 */
package com.gomeplus.commons.quartz.factory;

import io.netty.channel.Channel;

import java.util.List;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gomeplus.commons.quartz.cache.QuartzConstants;
import com.gomeplus.commons.quartz.cache.QuartzPropertiesCache;
import com.gomeplus.commons.quartz.dao.TaskConfigInfoDao;
import com.gomeplus.commons.quartz.netty.NettyMessage;
import com.gomeplus.commons.quartz.netty.client.NettyClientStartup;
import com.gomeplus.frame.factory.SpringBeanFactory;

/**
 * @author chenmin-ds
 * 任务配置信息加载初始化
 */
public class TaskInfoLoadInitsFactory {
	
	private Logger logger = LoggerFactory.getLogger("TimerTaskStartFactory");

	public List<JSONObject> loadTaskInfoDao(){
		try{
			TaskConfigInfoDao taskConfigInfoDao = (TaskConfigInfoDao) SpringBeanFactory.getBean("taskConfigInfoDao");
			return taskConfigInfoDao.queryTaskList();
		}catch(Exception e){
			logger.error("本地加载任务配置信息异常",e);
		}
		return null;
	}
	
	public void loadTaskInfoRemote(){
		try{
			Channel channel = NettyClientStartup.getInstance().getChannel();
			NettyMessage nettyMessage = new NettyMessage(QuartzConstants.BUSINESS_TYPE_RWXXCX_INITS);
			nettyMessage.setJsonObject("BUSINESS_CODE", QuartzPropertiesCache.getBusinessCode());
			channel.writeAndFlush(nettyMessage);
		}catch(Exception e){
			logger.error("远程加载任务配置信息异常",e);
		}
	}
}
